﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using OfficeOpenXml;
using Payroll.BusinessLogic.CustomerManager;

namespace Payroll.BusinessLogic.ExportImport
{
    public partial class ExcelHelper
    {
        #region Methods
        public static void ExportCustomerToExcel(List<Customer> customerCollection, ref string filePath, string filetemplate)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            FileInfo fileInfoTemplate = new FileInfo(filetemplate);
            FileInfo filewrite = fileInfoTemplate.CopyTo(filePath);
            using (var xlsx = new ExcelPackage(filewrite))
            {
                ExcelWorksheet sheetCust = xlsx.Workbook.Worksheets[1];
                sheetCust.Name = "Customer List";
                sheetCust.Cells[1, 2].Value = string.Format("Customer List Export {0}", DateTime.Now);                
                int i = 4;
                int custCount = customerCollection.Count;
                if (custCount > 2)
                {
                    sheetCust.InsertRow(i, customerCollection.Count, i);
                }
                foreach (var customer in customerCollection)
                {
                    sheetCust.Cells[i, 1].Value = i - 3;
                    sheetCust.Cells[i, 2].Value = customer.CustName;
                    sheetCust.Cells[i, 3].Value = customer.CustCaseWork;
                    sheetCust.Cells[i, 4].Value = customer.CustDate;
                    sheetCust.Cells[i, 5].Value = customer.CustHour;
                    sheetCust.Cells[i, 6].Value = customer.CustDateOfBirth;
                    sheetCust.Cells[i, 7].Value = customer.CustPlate;
                    sheetCust.Cells[i, 8].Value = customer.CustParent;
                    sheetCust.Cells[i, 9].Value = customer.CustEmail;
                    sheetCust.Cells[i, 10].Value = customer.CustAddres;
                    sheetCust.Cells[i, 11].Value = customer.CustCompany;
                    sheetCust.Cells[i, 12].Value = customer.CustMobile;
                    sheetCust.Cells[i, 13].Value = customer.CustPhone;
                    sheetCust.Cells[i, 14].Value = customer.CustEdu;
                    sheetCust.Cells[i, 15].Value = customer.CustFax;
                    sheetCust.Cells[i, 16].Value = customer.CustLangue;
                    sheetCust.Cells[i, 17].Value = customer.CustCareer;
                    sheetCust.Cells[i, 18].Value = customer.isVisa ? "Bị từ chối":"Chưa bị từ chối";
                    sheetCust.Cells[i, 19].Value = customer.NationalName;
                    sheetCust.Cells[i, 20].Value = customer.CustYear;
                    sheetCust.Cells[i, 21].Value = customer.VisaNumber;
                    sheetCust.Cells[i, 22].Value = customer.isTravel ? "Có":"Không";
                    sheetCust.Cells[i, 23].Value = customer.TravelNation;
                    sheetCust.Cells[i, 24].Value = customer.TravelNote;
                    sheetCust.Cells[i, 25].Value = customer.CustSource;
                    sheetCust.Cells[i, 26].Value = customer.IsStudy == 0? "Có":"Không";
                    sheetCust.Cells[i, 27].Value = customer.IsStudy == 1 ? "Có" : "Không";
                    sheetCust.Cells[i, 28].Value = customer.IsStudy == 2 ? "Có" : "Không";
                    sheetCust.Cells[i, 29].Value = customer.IsStudy == 3 ? "Có" : "Không";
                    sheetCust.Cells[i, 30].Value = customer.CustNationalName;
                    sheetCust.Cells[i, 31].Value = customer.CustCity;
                    sheetCust.Cells[i, 32].Value = customer.CustState;
                    sheetCust.Cells[i, 33].Value = customer.CustLevel;
                    sheetCust.Cells[i, 34].Value = customer.CustStady;
                    sheetCust.Cells[i, 35].Value = customer.CustSchool;
                    sheetCust.Cells[i, 36].Value = customer.CustRelative;
                    sheetCust.Cells[i, 37].Value = customer.CustRelativeAddre;
                    sheetCust.Cells[i, 38].Value = customer.CustNote;
                    sheetCust.Cells[i, 39].Value = customer.CustFollowUpDate01;
                    sheetCust.Cells[i, 40].Value = customer.CustFollowUpDate02;
                    sheetCust.Cells[i, 41].Value = customer.CustFollowUpDate03;
                    sheetCust.Cells[i, 42].Value = customer.CustNewNex01;
                    sheetCust.Cells[i, 43].Value = customer.CustNewNex02;
                    sheetCust.Cells[i, 44].Value = customer.CustNewNex03;
                    sheetCust.Cells[i, 45].Value = customer.CustIsDate;
                    sheetCust.Cells[i, 46].Value = customer.CustSignature ? "Có" : "Không";
                    sheetCust.Cells[i, 47].Value = customer.studyTravelOther;
                    sheetCust.Cells[i, 48].Value = customer.ProDate;
                    sheetCust.Cells[i, 49].Value = customer.ProCurator;
                    sheetCust.Cells[i, 50].Value = customer.ProFullName;
                    sheetCust.Cells[i, 51].Value = customer.ProSource;
                    sheetCust.Cells[i, 52].Value = customer.ProSchool;
                    sheetCust.Cells[i, 53].Value = customer.ProProgram;
                    sheetCust.Cells[i, 54].Value = customer.ProDateOfAdmission;
                    sheetCust.Cells[i, 55].Value = customer.ProscheduledInterviewDate;
                    sheetCust.Cells[i, 56].Value = customer.ProOther;
                    sheetCust.Cells[i, 57].Value = customer.ProBaccalaureate;
                    sheetCust.Cells[i, 58].Value = customer.ProGraduateIndustry;
                    sheetCust.Cells[i, 59].Value = customer.ProGraduateYear;
                    sheetCust.Cells[i, 60].Value = customer.ProWorking;
                    sheetCust.Cells[i, 61].Value = customer.ProLearning;
                    sheetCust.Cells[i, 62].Value = customer.ProFinanIndustry;
                    sheetCust.Cells[i, 63].Value = customer.ProFinanCapital;
                    sheetCust.Cells[i, 64].Value = customer.ProFinanShipPapers;
                    sheetCust.Cells[i, 65].Value = customer.ProFinanRental;
                    sheetCust.Cells[i, 66].Value = customer.ProFinanOther;
                    sheetCust.Cells[i, 67].Value = customer.ProPropertyLand;
                    sheetCust.Cells[i, 68].Value = customer.ProPropertyAccountValue;
                    sheetCust.Cells[i, 69].Value = customer.ProPropertyCar;
                    sheetCust.Cells[i, 70].Value = customer.ProPropertyOther;
                    i += 1;
                }
                xlsx.Save();
            }
        }
        #endregion
    }
}
